package bud.advice;

import java.util.Arrays;

import lombok.extern.slf4j.Slf4j;

import org.aspectj.lang.ProceedingJoinPoint;

@Slf4j
public class LoggingAdvice {
	public Object aroundAdvice(ProceedingJoinPoint point){
		long startTime = System.currentTimeMillis();
		String className = point.getTarget().getClass().getSimpleName();
		String methodName = point.getSignature().getName();
		
		Object[] args = point.getArgs();
		Object retValue = null;
		try {
			if(log.isInfoEnabled()){
				log.info("target ClassName : {}", className);
				log.info("weaving 대상 메소드 : {}", methodName);
//				log.info("메소드 전달 Argument : {}", Arrays.toString(args));				
			}
			retValue = point.proceed(args);
			long endTime = System.currentTimeMillis();
			if (log.isDebugEnabled()){
				log.debug("메소드 리턴 값 : {}", retValue);
				log.debug("소요시간 : {}ms", (endTime-startTime));
				
			}
			return retValue;
		} catch (Throwable e) {
			throw new RuntimeException();
		}
		
	}
}
